package top.misspro.valheim.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.misspro.valheim.model.CommandResultModel;
import top.misspro.valheim.model.ServerInfoModel;
import top.misspro.valheim.service.SSHService;

/**
 * @author Evan
 */
@Controller
public class IndexController {

    @Autowired
    SSHService sshService;

    @PostMapping(path = "/exec")
    @ResponseBody
    public CommandResultModel post(ServerInfoModel serverInfoModel) {
        sshService.installValheim(serverInfoModel);
        return CommandResultModel.ready();
    }

    @GetMapping("/cmd")
    @ResponseBody
    public CommandResultModel get(String ip) {
        return sshService.getCommandResultByIP(ip);
    }
}
